1 //+------------------------------------------------------------------+
\r
2 //| Lets Go Where Price Goes EA, v1.0.0 |
\r
3 //| Copyright © 2011, trapule@gmail.com |
\r
4 //| trapule@gmail.com |
\r
5 //+------------------------------------------------------------------+
\r
6 #property copyright "Copyright © 2011, trapule@gmail.com"
\r
7 #property link "trapule@gmail.com"
\r
9 extern string info1 = "Magic number";
\r
10 extern int magicnumber = 20110110;
\r
11 extern string info2 = "Pip distance between levels";
\r
12 extern int levelpipdist = 20;
\r
13 extern string info3 = "Fixed lot for each order";
\r
14 extern double fixedlot = 0.01;
\r
15 extern string info4 = "Account growth (in account currency) to exit all open positions";
\r
16 extern double gainforclose = 10.0;
\r
20 double levelrefdown;
\r
22 //+------------------------------------------------------------------+
\r
23 //| expert initialization function |
\r
24 //+------------------------------------------------------------------+
\r
27 if (Digits==2 || Digits==3) pip=0.01;
\r
28 else if (Digits==4 || Digits==5) pip=0.0001;
\r
29 levelrefup = ndd(Bid+levelpipdist/2*pip);
\r
30 levelrefdown = ndd(levelrefup-levelpipdist*pip);
\r
34 //+------------------------------------------------------------------+
\r
35 //| expert deinitialization function |
\r
36 //+------------------------------------------------------------------+
\r
42 //+------------------------------------------------------------------+
\r
43 //| expert start function |
\r
44 //+------------------------------------------------------------------+
\r
50 if ((AccountEquity()-AccountBalance())>gainforclose)
\r
52 for (i=OrdersTotal()-1; i>=0; i--)
\r
54 OrderSelect(i, SELECT_BY_POS);
\r
56 if (OrderMagicNumber()==magicnumber && OrderSymbol()==Symbol())
\r
58 if (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
\r
59 OrderDelete(OrderTicket());
\r
61 if (OrderType()==OP_BUY)
\r
62 OrderClose(OrderTicket(),OrderLots(),ndd(Bid),100);
\r
64 if (OrderType()==OP_SELL)
\r
65 OrderClose(OrderTicket(),OrderLots(),ndd(Ask),100);
\r
70 for (i=OrdersTotal()-1; i>=0; i--)
\r
72 OrderSelect(i, SELECT_BY_POS);
\r
74 if (OrderMagicNumber()==magicnumber && OrderSymbol()==Symbol())
\r
76 if (OrderType()==OP_BUYSTOP) bsn++;
\r
77 if (OrderType()==OP_SELLSTOP) ssn++;
\r
79 if (OrderType()==OP_BUY)
\r
81 if (ndd(OrderStopLoss())!=ndd(OrderOpenPrice()) && ndi((Bid-OrderOpenPrice())/pip)>=levelpipdist)
\r
82 OrderModify (OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), 0.0, 0);
\r
85 if (OrderType()==OP_SELL)
\r
87 if (ndd(OrderStopLoss())!=ndd(OrderOpenPrice()) && ndi((OrderOpenPrice()-Ask)/pip)>=levelpipdist)
\r
88 OrderModify (OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), 0.0, 0);
\r
93 if (bsn==0 && ssn==0)
\r
95 levelrefup = ndd(Bid+levelpipdist/2*pip);
\r
96 levelrefdown = ndd(levelrefup-levelpipdist*pip);
\r
97 OrderSend (Symbol(), OP_BUYSTOP, fixedlot, levelrefup, 100, levelrefdown, 0.0, "Lets Go Where Price Goes", magicnumber);
\r
98 OrderSend (Symbol(), OP_SELLSTOP, fixedlot, levelrefdown, 100, levelrefup, 0.0, "Lets Go Where Price Goes", magicnumber);
\r
101 if (Ask>=levelrefup)
\r
103 levelrefup = ndd(levelrefup+levelpipdist*pip);
\r
104 levelrefdown = ndd(levelrefup-2*levelpipdist*pip);
\r
105 OrderSend (Symbol(), OP_BUYSTOP, fixedlot, levelrefup, 100, levelrefdown, 0.0, "Lets Go Where Price Goes", magicnumber);
\r
106 OrderSend (Symbol(), OP_SELLSTOP, fixedlot, levelrefdown, 100, levelrefup, 0.0, "Lets Go Where Price Goes", magicnumber);
\r
109 if (Bid<=levelrefdown)
\r
111 levelrefdown = ndd(levelrefdown-levelpipdist*pip);
\r
112 levelrefup = ndd(levelrefdown+2*levelpipdist*pip);
\r
113 OrderSend (Symbol(), OP_BUYSTOP, fixedlot, levelrefup, 100, levelrefdown, 0.0, "Lets Go Where Price Goes", magicnumber);
\r
114 OrderSend (Symbol(), OP_SELLSTOP, fixedlot, levelrefdown, 100, levelrefup, 0.0, "Lets Go Where Price Goes", magicnumber);
\r
119 //+------------------------------------------------------------------+
\r
121 double ndd (double Price)
\r
123 return (NormalizeDouble(Price,Digits));
\r
125 //+------------------------------------------------------------------+
\r
127 double ndi (double Value)
\r
129 return (NormalizeDouble(Value,0));
\r
131 //+------------------------------------------------------------------+
\r